package org.example.springboot.controller;
import org.example.springboot.model.Suppliers;
import org.example.springboot.service.SuppliersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin(origins = "*", maxAge = 3600)
public class SuppliersController {
    @Autowired
    private SuppliersService suppliersService;

    @PostMapping("/insertSuppliers")
    public String insertSuppliers(@RequestBody Suppliers suppliers){
        return suppliersService.insertSuppliers(suppliers.getSupplierName(),suppliers.getAddress(),suppliers.getWebsite(),suppliers.getStatus(),suppliers.getBankName(),suppliers.getBankAccount(),suppliers.getContactPerson(),suppliers.getContactPhone(),suppliers.getDescription());
    }

    @GetMapping("/getAllSuppliers")
    public List<Suppliers> getAllSuppliers(){
        return suppliersService.getAllSuppliers();
    }

    @GetMapping("/getAllSuppliersName")
    public List<Suppliers> getAllSuppliersName(){
        return suppliersService.getAllSuppliersName();
    }

    @GetMapping("/findSuppliers/{keyword}")
    public List<Suppliers> findSuppliers(@PathVariable String keyword){
        return suppliersService.findSuppliers(keyword);
    }

    @DeleteMapping("/deleteById/{id}")
    public void deleteById(@PathVariable int id){
        suppliersService.deleteById(id);
    }

    @GetMapping("/findSuppliersById/{id}")
    public Suppliers findSuppliersById(@PathVariable int id){
        return suppliersService.findSuppliersById(id);
    }
}
